#ifndef ENUMCONVERTERCLEANUP_H_
#define ENUMCONVERTERCLEANUP_H_

#include <e32std.h>

#include "EnumConverterDefs.h"

class REnumConverterCleanup
    {
public:
    static REnumConverterCleanup & Instance();
    void CreateL();
    void Close();
    
private:
    // Mostly duplicating stuff in TCleanupItem, because vital parts of it are private :/
    template<typename T> struct CloseCaller { static void Close(TAny * aItem) { static_cast<T *>(aItem)->Close(); } };
    
public:
    
    template<typename T>
    void AddItemL(T & aItem)
        { iCloseItems.AppendL(TCloseStruct(&aItem, &CloseCaller<T>::Close)); }
    
private:
    
    struct TCloseStruct
        {
        typedef void (*CloseCallback)(TAny *);
        TCloseStruct(TAny * aObj, CloseCallback aCallback) : iObj(aObj), iCallback(aCallback) {}
        void Close() { (*iCallback)(iObj); }
    private:
        TAny * iObj;
        CloseCallback iCallback;
        };
    
private:
    RArray<TCloseStruct> iCloseItems;
    static REnumConverterCleanup * iInstance;
    };

#endif /* ENUMCONVERTERCLEANUP_H_ */
